//
//  ChooseJobCtrl.m
//  laowu
//
//  Created by Northwan on 15/5/8.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "ChooseJobCtrl.h"
#import "PublishDateCell.h"
#define CHOOSE_LABEL_INSERT 15

@interface ChooseJobCtrl ()<UITableViewDataSource,UITableViewDelegate>
@property(weak, nonatomic) IBOutlet UIView *saveChooseJobView;
@property(weak,nonatomic)IBOutlet UITableView *tableView;
@property(strong,nonatomic)NSMutableArray *jobDefaultArray;
@property(strong,nonatomic)NSMutableArray *jobChooseArray;
@property(strong,nonatomic)UIView *containerView;
@end

@implementation ChooseJobCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"选择岗位"];
    [self initJobArray];
    [self initTableView];
}

-(void)initJobArray{
      _jobDefaultArray = [NSMutableArray arrayWithObjects:@"木工",@"油漆工",@"普工",@"电工",@"钳工",@"切割",@"焊工",@"钣金工",@"车工",@"洗工",@"缝纫工",@"锅炉工",@"制冷/水暖工",@"综合维修工",@"铲车/叉车工",@"模具工",@"操作工",@"包装工",@"水泥工",@"钢筋工",@"组装工",@"瓦工",@"管道工",@"建筑工程师",@"道路桥梁建设",@"测绘/测量",@"工程监理",@"综合布线/弱电", nil];
      _jobChooseArray = [NSMutableArray array];
    
    /*木工,油漆工,普工,电工,钳工,切割,焊工,钣金工,车工,洗工,缝纫工,锅炉工,制冷/水暖工,综合维修工,铲车/叉车工,模具工,操作工,包装工,水泥工,钢筋工,组装工,瓦工,管道工,建筑工程师,道路桥梁建设,测绘/测量,工程监理,综合布线/弱电*/
    
}

-(void)initTableView{
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
}

-(void)reloadContainerJobView{
   NSString *jobName =  _jobChooseArray[_saveChooseJobView.subviews.count];
   UILabel *label = [self getLabel:jobName];
   CGSize labelSize = [jobName sizeWithFont:[UIFont systemFontOfSize:14]];
    if(_saveChooseJobView.subviews.count == 0){
        [label setFrame:CGRectMake(CHOOSE_LABEL_INSERT, _saveChooseJobView.height/2-labelSize.height/2, SCREENW/3-CHOOSE_LABEL_INSERT*2, labelSize.height)];
    }else if(_saveChooseJobView.subviews.count == 1){
        [label setFrame:CGRectMake(CHOOSE_LABEL_INSERT*2+SCREENW/3-CHOOSE_LABEL_INSERT*2, _saveChooseJobView.height/2-labelSize.height/2, SCREENW/3-CHOOSE_LABEL_INSERT*2, labelSize.height)];
    }else{
        [label setFrame:CGRectMake(CHOOSE_LABEL_INSERT*3+(SCREENW/3-CHOOSE_LABEL_INSERT*2)*2, _saveChooseJobView.height/2-labelSize.height/2, SCREENW/3-CHOOSE_LABEL_INSERT*2, labelSize.height)];
    }
    [_saveChooseJobView addSubview:label];
}

-(UILabel *)getLabel:(NSString *)jobName{
    UILabel *jobNameLabel = [[UILabel alloc]init];
    [jobNameLabel setFont:[UIFont systemFontOfSize:14]];
    [jobNameLabel setText:jobName];
    [jobNameLabel setTextAlignment:NSTextAlignmentCenter];
    [jobNameLabel setCornerRadius:0 borderWidth:1 borderColor:HEXColor(@"#dfdfdf")];
    return jobNameLabel;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _jobDefaultArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PublishDateCell *cell = [PublishDateCell cellWithTableView:tableView indexPath:indexPath];
    [cell initData:_jobDefaultArray[indexPath.row]];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return PublishDateCellHeight;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(_jobChooseArray.count < 3){
        [_jobChooseArray addObject:_jobDefaultArray[indexPath.row]];
        [self reloadContainerJobView];
    }else{
        [DialogUtils showTipsWithView:self.view String:@"最多选择三个岗位"];
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter]postNotificationName:nortif_job_choose_finish object:_jobChooseArray];
}

@end
